package com.dingyh.shopwebbackground.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dingyh.shopwebbackground.entity.Commodity;
import com.dingyh.shopwebbackground.mapper.CommodityMapper;
import com.dingyh.shopwebbackground.service.CommodityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dingyuhan
 * @since 2023-02-14
 */
@Service
public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity> implements CommodityService {


    @Autowired
    CommodityMapper commodityMapper;


    public List<Commodity> allGoods(Map<String,Object> map){
        return commodityMapper.allGoods(map);
    }

    public List<Commodity> isPushHome(Map<String,Object> map){
        return commodityMapper.isPushHome(map);
    }

    public List<Commodity> allGoodsByCompany(Map<String,Object> map){
        return commodityMapper.allGoodsByCompany(map);
    }

    public List<Commodity> allGoodsBySaleMonth(Map<String,Object> map){
        return commodityMapper.allGoodsBySaleMonth(map);
    }


    public Commodity addGoods(Map<String,Object> map){
        return commodityMapper.selectOne((Wrapper<Commodity>) map);
    }

    public List<Commodity> selectByName(Map<String,Object> map){
        return commodityMapper.selectByName(map);
   }


        public Commodity selectGoods(String id){
        LambdaQueryWrapper<Commodity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Commodity::getId,id);
        return baseMapper.selectOne(queryWrapper);
    }

    public boolean removeGoods(String id){
        try {
            return removeById(id);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
    }

    @Override
    public boolean updStock(Commodity commodity) {
        try {
            return updateById(commodity);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
    }

    @Override
    public boolean updMonth(String id, BigDecimal month) {
        Commodity commodity = new Commodity();
        commodity.setId(id);
        commodity.setMonth(month);
        try {
            return updateById(commodity);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
    }
}
